Calling a C function from JavaScript

Once you know how C-level extensibility works in Dreamweaver and the data types and functions it relies on, it's useful to walk through an example of how to build a library and call a function.

This exercise requires three files, which are included in the Extending/c_files folder inside the Dreamweaver application folder:

mm_jsapi.h is a header file that includes definitions for all the data types and functions described in The C-level extensibility API.
Sample.c is an example file that defines the computeSum() function.
Sample.mak is a makefile that you can use to build Sample.c into a DLL with Microsoft Visual C++; Sample.proj is the equivalent file for building a CFM Library with Metrowerks CodeWarrior. If you are using another tool, you can create the makefile yourself.

To build the DLL in Windows:

1 In Microsoft Visual C++, choose File > Open Workspace and select Sample.mak.
2 Choose Build > Rebuild All.
When the build operation is complete, a file called Sample.dll appears in the folder containing Sample.mak (or one of its subfolders).

To build the shared library on the Macintosh:

1 Open Sample.proj in Metrowerks CodeWarrior.
2 Build the project to generate a CFM Library.
When the build operation has finished, a file called Sample appears in the folder containing Sample.proj (or in one of its subfolders).

To call the computeSum() function from the Insert Horizontal Rule object:

1 In the Configuration folder within the Dreamweaver application folder, create a folder called JSExtensions.
2 Copy Sample.dll (Windows) or Sample (Macintosh) to the JSExtensions folder.
3 In a text editor, open the file called horizontal_rule.htm that resides in the Configuration/Objects/Common folder.
4 Add the line alert(Sample.computeSum(2,2)); to the objectTag() function so that it appears as follows:
function objectTag() {
  // Return the html tag that should be inserted
  alert(Sample.computeSum(2,2));
  return "<HR>";
}
5 Save the file and restart Dreamweaver.

To execute the computeSum() function:

Choose Insert > Horizontal Rule. A dialog box containing the number 4—the result of computing the sum of 2 plus 2—appears.